package com.matriq.cloudmanager;

import com.matriq.cloudmanager.R;
import com.matriq.cloudmanager.dialog.ConfirmDialog;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.ToggleButton;
import net.lgpage.activity.BaseActivity;
import net.lgpage.dialog.DialogListener;
import net.lgpage.tool.ImageTool;

public class SetActivity extends BaseActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ac_set);
		setViews();
		setEvents();
		loadData();
	}

	ToggleButton tg_push;
	LinearLayout ll[] = new LinearLayout[5];
	ScrollView sv;
	TextView tv_title;
	ToggleButton tg_wifiplay;
	ImageButton ll_back;

	Button bt_logout;
	private void setViews() {
		tg_push = (ToggleButton) this.findViewById(R.id.tg_push);
		ll[0] = (LinearLayout) this.findViewById(R.id.ll0);
		ll[1] = (LinearLayout) this.findViewById(R.id.ll1);
		ll[2] = (LinearLayout) this.findViewById(R.id.ll2);
		ll[3] = (LinearLayout) this.findViewById(R.id.ll3);
		ll[4] = (LinearLayout) this.findViewById(R.id.ll4);
		sv = (ScrollView) this.findViewById(R.id.sv);
		tv_title = (TextView) this.findViewById(R.id.tv_title);
		tg_wifiplay = (ToggleButton) this.findViewById(R.id.tg_wifiplay);
		ll_back = (ImageButton) this.findViewById(R.id.ll_back);
		bt_logout = (Button) this.findViewById(R.id.bt_logout);
		
	}

	private void setEvents() {
		bt_logout.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				MyApp.getApp().outLogin();
				getActivity().finish();
				toActivity(LoginActivity.class);
			}
		});
		tg_push.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				putAppValue("push", isChecked);
				MyApp.getApp().setPush(isChecked);
			}
		});
		tg_wifiplay.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				putAppValue("notwifiplay", isChecked);
				MyApp.getApp().setNotwifiplay(isChecked);
			}
		});
		ll[0].setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				toActivity(SuggestActivity.class);
			}
		});
		ll[2].setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ConfirmDialog d = new ConfirmDialog(getActivity());
				d.setData("是否清除缓存?");				d.setListener(new DialogListener() {

					@Override
					public void onDialogExecute(Object... obj) {
						ImageTool.clearCache();
					}
				});
				d.show();
			}
		});
		ll[4].setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				toActivity(VersionActivity.class);
			}
		});
	}

	Object obj;

	public void setData(Object obj) {
		this.obj = obj;
		tv_title.setText(null);
	}

	private void loadData() {
		boolean push = (boolean) load("push", true);
		tg_push.setChecked(push);
		boolean notwifiplay = (boolean) load("notwifiplay", false);
		tg_wifiplay.setChecked(notwifiplay);
		
	}

	@Override
	public void onDestroy() {

		super.onDestroy();
	}

}